home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1244 / procapp1.c < prev    next >
C/C++ Source or Header  |  1996-06-17  |  4KB  |  151 lines

  1. #include <windows.h>
  2. #include "procbox.h"
  3.  
  4.  
  5. int CALLBACK _export PBCallback(HWND, int , LPARAM);
  6.  
  7. ////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //    PROCAPP1.C    - Demonstrates use of ProcessBox Single Callback Interface
  10. //                    
  11. //                    - Contains code for 
  12. //                            - WinMain Entry Point
  13. //                            - WndProc
  14.     
  15. LRESULT FAR PASCAL _export WndProc(HWND, UINT, WPARAM, LPARAM);
  16.  
  17.                
  18. char        szAppName[] = "PROCAPP1";
  19. char        szWindowText[] = "ProcessBox - Single Callback Modal Interface Demo";
  20.                            
  21.  
  22. /////////////////////////////////////////////////
  23. //
  24. //
  25. //     WndProc     
  26. //
  27.  
  28. LRESULT FAR PASCAL _export WndProc (HWND hwnd, UINT message, 
  29.                                                 WPARAM wParam, LPARAM lParam)
  30. {  
  31.     FARPROC    lpfnPBCallback;
  32.     char    szText[64];
  33.     
  34.     switch (message)
  35.     {
  36.         case WM_KEYDOWN:                
  37.         case WM_LBUTTONDOWN:
  38.            lpfnPBCallback = MakeProcInstance((FARPROC)PBCallback, GetWindowWord(hwnd, GWW_HINSTANCE));    
  39.             
  40.             wsprintf(szText, "Returned: %d",
  41.                     ProcessBox(hwnd, "Processing...", lpfnPBCallback));    // it's that easy!
  42.             
  43.             MessageBox(hwnd, szText, NULL, NULL);
  44.             
  45.             FreeProcInstance(lpfnPBCallback);
  46.         return 0;        
  47.  
  48.         case WM_DESTROY:
  49.             PostQuitMessage(0);
  50.         return 0;        
  51.     }
  52.    return DefWindowProc (hwnd, message, wParam, lParam );
  53. }
  54.  
  55. ///////////////////////////////////////////////////////////
  56. //
  57. //    The Process Box Callback
  58. //
  59. //      
  60. int CALLBACK _export PBCallback(HWND hwndPB, int iCode, LPARAM lUserData)
  61. {
  62.     static     i;    
  63.     long        j;       
  64.         
  65.     switch (iCode)
  66.     {
  67.         case PBC_OPEN:            
  68.             // allocate memory here
  69.             i=0;
  70.         return TRUE;    
  71.         
  72.         case PBC_CLOSE:
  73.             // free memory here
  74.         return TRUE;
  75.         
  76.         case PBC_CANCEL:
  77.         return (    MessageBox(NULL, "Really cancel operation?", "Message Box", 
  78.                         MB_APPLMODAL|MB_YESNO)==IDYES ? TRUE : FALSE );
  79.                             
  80.             
  81.         case PBC_PROCESS:
  82.             for (j=0; j<0xEFF; j++);    // processing ! 
  83.             i++;
  84.                         
  85.             if (i>10000)
  86.                 return PBCR_END;
  87.             
  88.             if (i==5000)             
  89.                 SetWindowText(hwndPB, "Reached halfway!");
  90.                         
  91.             SendMessage(hwndPB, PM_SETGAUGE, i/100, 0l);
  92.             return PBCR_CONTINUE;
  93.             
  94.         default:  
  95.             i++;
  96.     }
  97.     return TRUE;
  98. }
  99.  
  100. /////////////////////////////////////////////////
  101. //
  102. //
  103. //     WinMain - Entry Point
  104. //
  105. //
  106. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  107.                     LPSTR lpszCmdParam, int nCmdShow)
  108. {     
  109.        
  110.     MSG             msg ;
  111.     WNDCLASS        wndclass ;       
  112.     HWND                hwnd;
  113.         
  114.     if (!hPrevInstance) 
  115.     {
  116.         wndclass.style         = NULL ;
  117.         wndclass.lpfnWndProc   = WndProc ;
  118.         wndclass.cbClsExtra    = 0 ;
  119.         wndclass.cbWndExtra    = 0 ;
  120.         wndclass.hInstance     = hInstance ;
  121.         wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION) ;
  122.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  123.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  124.         wndclass.lpszMenuName  = NULL ;
  125.         wndclass.lpszClassName = szAppName ;
  126.                 
  127.         RegisterClass (&wndclass) ;
  128.     }
  129.         
  130.     hwnd = CreateWindow (    szAppName,             // class
  131.                                      szWindowText,            // window text
  132.                                     WS_OVERLAPPEDWINDOW,            // style
  133.                                     CW_USEDEFAULT, CW_USEDEFAULT,        // x, y start
  134.                                     CW_USEDEFAULT, CW_USEDEFAULT,        // width, height
  135.                                     NULL,             // parent window handle
  136.                                     NULL,             // menu handle
  137.                                     hInstance,         // instance handle
  138.                                     NULL) ;            // long pointer to creation data
  139.  
  140.     ShowWindow (hwnd, nCmdShow) ;
  141.     UpdateWindow (hwnd) ;
  142.            
  143.     while (GetMessage (&msg, NULL, 0, 0))
  144.     {
  145.         TranslateMessage (&msg) ;
  146.         DispatchMessage (&msg) ;
  147.     }
  148.     
  149.     return msg.wParam ;   
  150. }  
  151.